<!DOCTYPE html>
<title>No crash when resetting player just after requesting PIP</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<video></video>
<script>
async_test(t => {
  if (!document.pictureInPictureEnabled)
    t.done();

  const video = document.querySelector('video');
  video.src = '../content/test.ogv';

  video.addEventListener('click', t.step_func_done(() => {
    video.requestPictureInPicture();
    video.src = '';
    // Do not crash.
  }), { once: true });

  video.play().then(t.step_func(() => {
    const bounds = video.getBoundingClientRect();

    chrome.gpuBenchmarking.pointerActionSequence([{
      source: 'mouse',
      actions: [
        { name: 'pointerDown',
          x: bounds.left + bounds.width / 2,
          y: bounds.top + bounds.height / 2
        },
        { name: 'pointerUp' }
      ]
    }]);
  }));
});
</script>
